package com.example.user.controller.admin;

import com.example.framework.common.pojo.R;
import com.example.framework.security.core.LoginUser;
import com.example.framework.security.core.annotation.LoggedInUser;
import com.example.user.controller.admin.vo.AdminUserInfoRespVO;
import com.example.user.service.admin.AdminService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@Tag(name = "管理员功能")
@RestController
@RequestMapping("/admin")
public class AdminController {

    @Resource
    private AdminService adminService;

    @PreAuthorize("hasAuthority('admin')")
    @Operation(summary = "踢人下线")
    @GetMapping("/account/kick")
    public R<?> kickAccount(@RequestParam String userId, @RequestParam(required = false) String deviceId) {
        adminService.kickAccount(userId, deviceId);
        return R.success("操作成功");
    }

    @Operation(summary = "查询当前登录的用户信息")
    @GetMapping("/getUserInfo")
    public R<AdminUserInfoRespVO> getUserInfo(@LoggedInUser LoginUser loginUser) {
        AdminUserInfoRespVO adminUserInfoRespVO = new AdminUserInfoRespVO()
                .setUserId(loginUser.getUsername())
                .setName(loginUser.getNickname())
                .setDeviceId(loginUser.getDeviceId())
                .setPermissions(loginUser.getPermissions());
        return R.success(adminUserInfoRespVO);
    }

}
